import urllib.request as ur
import  lxml.etree as le


proxy_address = ur.urlopen('http://api.ip.data5u.com/dynamic/get.html?order=c1411144dca927c756f66be0c1e0ec81&sep=4').read().decode('utf-8').strip()

#创建
proxy_handler = ur.ProxyHandler(
    {
        'http':proxy_address
    }
)

proxy_opener = ur.build_opener(proxy_handler)

requset = ur.Request('https://edu.csdn.net/')

reponse = proxy_opener.open(requset).read()

html_xs = le.HTML(reponse)

div_xs = html_xs.xpath('//div[contains(@class,"classify_cList")]')

# print(div_xs)

data_s = []

for div_x in div_xs:
    Class_A = div_x.xpath('./h3/a/text()')
    Class_B = div_x.xpath('./div/span/a/text()')

    data_s.append(
        {
            'Class_A': Class_A[0],
            'Class_B': Class_B
        }
    )

for data in data_s:
    print(data.get('Class_A'))
    for class_B in data.get('Class_B'):
        print('    ', class_B)

